package com.cskaoyan.controller.lzp_controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.lzp.*;
import com.cskaoyan.lz_service.FootService;
import com.cskaoyan.service.GoodsService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * \* Description:
 * \* @author: Lizhanpeng
 * \* Date: 2022/5/8
 * \
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("count")
    public BaseRespVo goodsCount(){
        Integer i =  goodsService.goodsCount();
        return BaseRespVo.listOk(i);
    }

    @GetMapping("category")
    public BaseRespVo goodsCategory(Integer id){
        GoodsCategoryVO goodsCategoryVO = goodsService.goodsCategory(id);
        return BaseRespVo.listOk(goodsCategoryVO);
    }

    @GetMapping("list")
    public BaseRespVo goodsList(GoodsWxListBO goodsWxListBO){
        Subject subject = SecurityUtils.getSubject();
        Integer id = (Integer) subject.getPrincipals().getPrimaryPrincipal();

        GoodsWxListVO goodsWxListVO= goodsService.goodsWxList(goodsWxListBO,id);
        return BaseRespVo.listOk(goodsWxListVO);
    }

    @Autowired
    FootService footService;

    @GetMapping("detail")
    public BaseRespVo goodsDetail(Integer id){


        Subject subject = SecurityUtils.getSubject();
        Integer userId = (Integer) subject.getPrincipals().getPrimaryPrincipal();

        GoodsWxDetailVO goodsWxDetailVO = goodsService.goodsWxDetail(id,userId);

        //插入浏览足迹

        footService.insertFootprint(id,userId);

        return BaseRespVo.listOk(goodsWxDetailVO);
    }

    @GetMapping("related")
    public BaseRespVo goodsRelated(Integer id){
        GoodsWxRelatedVO goodsWxRelatedVO = goodsService.goodsWxRelated(id);
        return BaseRespVo.listOk(goodsWxRelatedVO);
    }
}
